package com.uwlaser.rest;

import com.uwlaser.annotation.Log;
import com.uwlaser.service.FactoryShiftService;
import com.uwlaser.service.dto.FactoryShiftDto;
import com.uwlaser.service.dto.FactoryShiftQueryParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
* @author huangpan
* @date 2022-12-02
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "班次信息管理")
@RequestMapping("/api/factoryShift")
public class FactoryShiftController {

    private final FactoryShiftService factoryShiftService;

    @GetMapping
    @Log("查询班次信息")
    @ApiOperation("查询班次信息")
    @PreAuthorize("@el.check('shiftDetails:list')")
    public ResponseEntity query(FactoryShiftQueryParam query, Pageable pageable){
        return new ResponseEntity<>(factoryShiftService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增班次信息")
    @ApiOperation("新增班次信息")
    @PreAuthorize("@el.check('factoryShift:add')")
    public ResponseEntity create(@Validated @RequestBody FactoryShiftDto resources){
        return new ResponseEntity<>(factoryShiftService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改班次信息")
    @ApiOperation("修改班次信息")
    @PreAuthorize("@el.check('factoryShift:edit')")
    public ResponseEntity update(@Validated @RequestBody FactoryShiftDto resources){
        factoryShiftService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除班次信息")
    @ApiOperation("删除班次信息")
    @PreAuthorize("@el.check('factoryShift:del')")
    public ResponseEntity delete(@RequestBody Set<Integer> ids) {
        factoryShiftService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出班次信息")
    @ApiOperation("导出班次信息")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('factoryShift:list')")
    public void download(HttpServletResponse response, FactoryShiftQueryParam query) throws IOException {
        factoryShiftService.download(factoryShiftService.queryAll(query), response);
    }*/

}
